#!/bin/bash

ip=192.168.1.224

err_exit() {
    echo $1
    exit $2
}


apt_config() {
    cat > /etc/apt/sources.list << EOF
deb http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-security main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-updates main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-proposed main restricted universe multiverse
deb-src http://mirrors.aliyun.com/ubuntu/ xenial-backports main restricted universe multiverse
EOF
    apt update
}

lang_install() {
    apt install language-pack-gnome-zh* language-pack-zh* -y
    # language-pack-gnome-zh-hans-base language-pack-zh-hans language-pack-zh-hans-base
    apt install libreoffice-l10n-zh-cn libreoffice-help-zh-cn       \
                thunderbird thunderbird-locale-zh-hans              \
                thunderbird-locale-zh-cn thunderbird-gnome-support -y
}

fcitx_install() {
    apt-get install fcitx fcitx-table-wbpy fcitx-ui-classic         \
                    fcitx-config-gtk fcitx-frontend-gtk3            \
                    fcitx-pinyin fcitx-sunpinyin fcitx-table-wubi   \
                    fonts-arphic-ukai fonts-arphic-uming -y

    sed -i 's/^run_im .*$/run_im fcitx/' ~/.xinputrc

    # fcitx-frontend-all
    # fcitx-frontend-fbterm
    # fcitx-frontend-gtk2
    # fcitx-frontend-qt4
    # fcitx-frontend-qt5
    # fcitx-libs-qt
    # fcitx-libs-qt5
    # fcitx-module-kimpanel
    # fcitx-module-lua
    # fcitx-tools
    # fcitx-ui-light
    # gir1.2-fcitx-1.0
}

soft_install() {
    apt remove vim-common -y
    apt install vim git tmux gcc libc6-dev nfs-kernel-server        \
                chromium-browser mplayer openssh-server remmina* -y
}

ktouch_install() {
    sudo apt remove ktouch -y
    sudo apt install cmake g++ kdelibs5-dev libqglviewer-dev-qt4 -y
    wget http://$ip/ktouch.tar
    tar -xf ktouch.tar
    cd ktouch
    make -j4
    sudo make install
    cd ..
}

vim_config() {
    local oldpwd=$(pwd)
    sudo mount $ip:/kyo /mnt
    cp /mnt/kyo_vim ~/kyoVim -rfapuv
    cd ~/kyoVim
    ./linux_install.sh
    cd $oldpwd
}

test $UID -ne 0 && err_exit "请使用sudo运行!!!" 1

# 源设置
apt_config
# 语言包
lang_install
# 输入法
fcitx_install
# nfs vim git ssh vnc
soft_install
# 打字程序
ktouch_install
# vim配置
vim_install

